<?php

class DefaultController extends Controller
{
    public $layout = '//layouts/admin';
    
    /**
     * @return array action filters
     */
    public function filters() {
        return CMap::mergeArray(parent::filters(), array(
            'accessControl', // perform access control for CRUD operations
        ));
    }

    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules() {
        $arrayUser = array_merge(Yii::app()->getModule('user')->getAdmins(),Yii::app()->getModule('user')->getSuppliers());
        return array(
            array('allow', // allow admin user to perform 'admin' and 'delete' actions
                'actions' => array('index','default','admin', 'delete', 'create', 'update', 'view','active','lock','unlock','upgrade'),
                'users' => $arrayUser,
            ),
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }
    
    public function actionIndex()
	{   
		$model=new User('search');
		$model->unsetAttributes();  // clear any default values
                $model->superuser = User::S_SUPPLIER;
                $model->status = User::STATUS_NOACTIVE;
		if(isset($_GET['User']))
			$model->attributes=$_GET['User'];
                $sup_new = $model->countByAttributes(array('status'=>User::STATUS_NOACTIVE,'superuser'=>User::S_SUPPLIER));
                
                $model2= new User('search');
		$model2->unsetAttributes();  // clear any default values
                $model2->superuser = User::S_TRANSPORTER;
                $model2->status = User::STATUS_NOACTIVE;
		if(isset($_GET['User']))
			$model2->attributes=$_GET['User'];
                $tran_new = $model2->countByAttributes(array('status'=>User::STATUS_NOACTIVE,'superuser'=>User::S_TRANSPORTER));

		$this->render('index',array(
                        'sup_new'=>$sup_new,
                        'tran_new'=>$tran_new,
                        'sups'=>$model,
			'trans'=>$model2,
		));

	}
}